package cn.edu.ahstu.acm.controller;

import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.ahstu.acm.entity.Status;
import cn.edu.ahstu.acm.entity.User;
import cn.edu.ahstu.acm.exception.UserException;
import cn.edu.ahstu.acm.mapper.UserMapper;

@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserMapper userMapper;

	@RequestMapping("/userlist/{page}/{offset}")
	public String findList(@PathVariable Long page, @PathVariable Long offset) {
		return "userlist";
	}
	
	
	@RequestMapping("/userinfo/{uid}")
	public String find(@PathVariable Long uid, Model model) {
		
		List<Integer> problemSolvedList=userMapper.queryByUidSolved(uid);
		
		List<Integer> problemNotSolvedList=userMapper.queryByUidNoSolved(uid);

		model.addAttribute("problemSolvedList", problemSolvedList);
		model.addAttribute("problemNotSolvedList", problemNotSolvedList);

		User user = userMapper.query(uid);
		if (user == null) {
			throw new UserException("用户不存在");
		}
		model.addAttribute("user", user);
		return "userinfo";
	}

	@RequestMapping("/regist")
	public String regist(User user) {

		return "regist";
	}

	@RequestMapping(value = "/update/{uid}", method = RequestMethod.GET)
	public String updatePage(@PathVariable Long uid, Model model) {
		User user = userMapper.query(uid);
		model.addAttribute("user", user);
		return "update";
	}

	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public String update(Long user) {

		return "";
	}

	@RequestMapping(value = "/login")
	public String login(User user) {
		return "login";
	}

	@RequestMapping(value = "/logout")
	public String logout() {
		return "index";
	}

	@RequestMapping("/remove")
	@ResponseBody
	public String remove(Long user) {

		return "";
	}

}
